package com.googlecode.c4e.ui.internal.preferences;

import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.RadioGroupFieldEditor;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.eclipse.ui.PlatformUI;

import com.googlecode.c4e.ui.ContinuumPlugin;
import com.googlecode.c4e.ui.views.ServersView;

public class ContinuumPreferencesPage extends FieldEditorPreferencePage
		implements IWorkbenchPreferencePage {

	private RadioGroupFieldEditor defaultLayout;

	public ContinuumPreferencesPage() {
		super(GRID);
		setTitle("View Presentation");
		setDescription("View Presentation");
		setPreferenceStore(ContinuumPlugin.getDefault().getPreferenceStore());
	}

	protected void createFieldEditors() {
		defaultLayout = new RadioGroupFieldEditor(
				IPreferenceIds.SERVERS_VIEW_PRESENTATION, "View Presentation",
				2, new String[][] { { ServersView.TREE, ServersView.TREE },
						{ ServersView.FLAT, ServersView.FLAT } },
				getFieldEditorParent(), true);
		addField(defaultLayout);
	}

	public void init(IWorkbench workbench) {
	}

	public boolean performOk() {
		ContinuumPlugin.getDefault().savePluginPreferences();
		ServersView serversView = (ServersView) PlatformUI.getWorkbench()
				.getActiveWorkbenchWindow().getActivePage().findView(
						"com.googlecode.c4e.ui.views.ServersView");
		if (serversView != null) {
			serversView.refreshViewer();
		}
		return super.performOk();
	}
}
